var nms = {
	device : {
	
		add : function (el) {
			$(el).css('display','none');
			$('#addDevice').addClass('discovering');
			$.dialog.resize();
			
			var inputs = $('#addDevice INPUT,#addDevice SELECT,#addDevice TEXTAREA ');
			console.log(inputs);
			var post = {};
			for (var i=0;i< inputs.length;i++) {
				if (inputs[i].name && inputs[i].name != '') {
					post[inputs[i].name] = inputs[i].value;
				}
			}
			post.action = 'adddevice';
			post.subAction = 'ping';
			$('#discoveryResults').append(
				$('<tr></tr>').attr('id','pingResult').append(
					$('<td></td>').attr({className:'iconActivitySml'})
				).append(
					$('<th></th>').text('Pinging Device...')
				)
			);
			$.post('/',post,function (data) {
				if (data.success && data.success == true) {
					$('#pingResult TD').attr({className:'iconTick'});
					$('#pingResult TH').html('Pinged Device - '+data.msg);
					//Stage 2 -SNMP Detection
					$('#discoveryResults').append(
						$(document.createElement('tr')).attr('id','snmpResult').append(
							$(document.createElement('td')).attr({className:'iconActivitySml'})
						).append(
							$(document.createElement('th')).text('Attempting to device Information via SNMP...')
						)
					);
					post.subAction = 'snmp';
					$.post('/',post,function (data) {
						if (data.success && data.success == true) {
							$('#snmpResult TD').attr({className:'iconTick'});
							post.description = data.msg;
							$('#snmpResult TH').html('Device '+data.msg+' responding to SNMP requests');
							$('#discoveryResults').append(
								$(document.createElement('tr')).attr('id','createResult').append(
									$(document.createElement('td')).attr({className:'iconActivitySml'})
								).append(
									$(document.createElement('th')).text('Creating Device '+post.description)
								)
							);
							post.subAction = 'create';
							$.post('/',post,function (data) {
								if (data.success && data.success == true) {
									
								} else {
									$('#createResult TD').attr({className:'iconCross'});
									if (data.msg == 'Unable to find IP Address') {
									
									} else if (data.msg == 'Action Not Found') {
										$('#createResult TH').html('Pinged Device - Server Side Error ('+data.msg+')');
									
									} else {
										$('#createResult TH').html('Polled  Device did not respond');
									}
								}
							},'json');
						} else {
							$('#snmpResult TD').attr({className:'iconCross'});
							if (data.msg == 'Unable to find IP Address') {
							
							} else if (data.msg == 'Action Not Found') {
								$('#snmpResult TH').html('Pinged Device - Server Side Error ('+data.msg+')');
							
							} else {
								$('#snmpResult TH').html('Polled  Device did not respond');
							}
						
						}
					},'json');
				} else {
					$('#pingResult TD').attr({className:'iconCross'});
					if (data.msg == 'Unable to find IP Address') {
					
					} else if (data.msg == 'Action Not Found') {
						$('#pingResult TH').html('Pinged Device - Server Side Error ('+data.msg+')');
					
					} else {
						$('#pingResult TH').html('Pinged  Device did not respond');
					}
				}
				console.log(data);
			},'json');
		}
	},
	status : {
		timer : null,
		start : function () {
			this.timer = setTimeout('nms.timer.refresh();',60000);
		},
		refresh : function () {
			$.post('/index.php',{template:'home'},function (html) {
				$('#body').html(html);
			});		
		},
		stop: function () {
			clearTImeout(this.timer);
		}
	}
};